﻿using DevExpress.Data;
using DevExpress.XtraGrid;
using DXApplicationTangche.UC.抖音出入库.Service;
using DXApplicationTangche.UC.生产计划.编排生产批.service;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace DXApplicationTangche.UC.抖音出入库
{
    public partial class Form抖音直播间看板 : DevExpress.XtraEditors.XtraForm
    {
        public Form抖音直播间看板()
        {
            InitializeComponent();
            this.refresh();
            this.refresh每款出入库汇总();
        }
        private void refresh()
        {
            //  数据更新时间
            try
            {
                DateTime pythonImportRecordDateTime = 抖音订单Service.getPythonImportRecordDateTime("t_barcode_in_stock");
                this.textBox数据更新时间.Text = pythonImportRecordDateTime.ToString();
            }
            catch { }
            /**
             * 上播需要看的款式库存
             */
            //  查询抖音生产计划数据
            List<DouyinOrderStockUpSummaryDTO> douyinOrderStockUpSummaryDTOs = 抖音订单Service.getDouyinStockInfo();
            List<DouyinOrderStockUpSummaryVO> list = new List<DouyinOrderStockUpSummaryVO>();
            foreach (DouyinOrderStockUpSummaryDTO item in douyinOrderStockUpSummaryDTOs)
            {
                list.Add(new DouyinOrderStockUpSummaryVO(item));
            }
            this.gridControl抖音生产计划.DataSource = list;
            this.bandedGridView抖音生产计划.GroupSummary.Add(new GridGroupSummaryItem(SummaryItemType.Sum, "stockIn", null, "(在库数量总合计 = {0})"));
            this.bandedGridView抖音生产计划.RefreshData();
            //  查询昨日下单的抖音备货一览
            //this.gridControl昨日下单待发货.DataSource = 抖音订单Service.getYesterdayDouyinOrderStockUps();
            //this.gridView抖音生产计划.RefreshData();
        }
        public void refresh每款出入库汇总()
        {
            /**
             * 每款出入库汇总
             */
            this.gridControl每款出入库汇总.DataSource = 编排生产批Service.getDouyinStockTitile(DateTime.Now.ToString("yyyy-MM-dd"));
            this.gridView每款出入库汇总.RefreshData();
            this.gridView入库汇总.RefreshData();
            this.gridView出库汇总.RefreshData();
        }
        private void gridView抖音生产计划_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
        {
            //  数量字段为0时不显示
            //  数量字段为0时不显示
            if (e.Column.Name.Equals("gridColumn未来3天发货量")
                || e.Column.Name.Equals("gridColumn未来三到七天发货量")
                || e.Column.Name.Equals("gridColumn七天以后发货量")
                || e.Column.Name.Equals("gridColumn订单数量")
                || e.Column.Name.Equals("gridColumn水洗数量")
                || e.Column.Name.Equals("gridColumn生产批入库数量")
                || e.Column.Name.Equals("gridColumn钉锁数量")
                || e.Column.Name.Equals("gridColumn手缝数量")
                || e.Column.Name.Equals("bandedGridColumn半成品检查数量")
                || e.Column.Name.Equals("gridColumn成品检查数量")
                || e.Column.Name.Equals("bandedGridColumn预库存")
                || e.Column.Name.Equals("bandedGridColumn成品库存")
                || e.Column.Name.Equals("bandedGridColumn凯丹库存")
                || e.Column.Name.Equals("bandedGridColumn柏威年库存")
                || e.Column.Name.Equals("bandedGridColumn在库数量合计")
                || e.Column.Name.Equals("gridColumn总数量")
                )
            {
                try
                {
                    if (Convert.ToString(e.Value).Equals("0"))
                    {
                        e.DisplayText = String.Empty;
                    }
                }
                catch { }
            }
        }
        private void gridView抖音生产计划_CellMerge(object sender, DevExpress.XtraGrid.Views.Grid.CellMergeEventArgs e)
        {
            if (e.Column.Name == "gridColumn图片")
            {
                Image image1 = (Image)bandedGridView抖音生产计划.GetRowCellValue(e.RowHandle1, e.Column);
                Image image2 = (Image)bandedGridView抖音生产计划.GetRowCellValue(e.RowHandle1, e.Column);
                e.Merge = image1 == image2;
                e.Handled = true;
            }
        }

        private void simpleButton导出excel_Click(object sender, EventArgs e)
        {
            SaveFileDialog fileDialog = new SaveFileDialog();
            fileDialog.Title = "导出Excel";
            fileDialog.Filter = "Excel文件(*.xls)|*.xls";
            DialogResult dialogResult = fileDialog.ShowDialog(this);
            if (dialogResult == DialogResult.OK)
            {
                DevExpress.XtraPrinting.XlsExportOptions options = new DevExpress.XtraPrinting.XlsExportOptions();
                this.gridControl抖音生产计划.ExportToXls(fileDialog.FileName);
                DevExpress.XtraEditors.XtraMessageBox.Show("保存成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        private void simpleButton刷新_Click(object sender, EventArgs e)
        {
            this.refresh每款出入库汇总();
        }
    }
}
